package com.shanzhe.eshop.common.jdk;

/**
 * @Author yinwei
 * @create 2021/12/6
 * @Version 1.0
 */
public class ThreadLocalDemo {

    public static void main(String[] args) {
        final ThreadLocal<Long> threadLocal = new ThreadLocal<Long>();
        threadLocal.set(1L);
        new Thread(){
            @Override
            public void run() {
                threadLocal.set(2L);
                System.out.println("线程1："+threadLocal.get());
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                threadLocal.set(3L);
                System.out.println("线程2："+threadLocal.get());
            }
        }.start();

        System.out.println("main线程："+threadLocal.get());
    }
}
